<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;

class Daili extends  Base
{


   
    public function index()
    {
         
   	$dailiData=Db::name('dailiconfig')->order('id desc')->select();
      return view('',[
         'dailiData'=>$dailiData,
        
        ]);
// 本程序由艾客网络  xaike.xyz开发并开源，QQ:2404503092
// 需要新版/多群版或二次开发的请联系我，源码为服务器打包，完美无错。
// 本源码为tp6内核，修改数据库配置文件在/config/database.php
// 运行目录为根目录   
// 艾客网络，承接网站开发/二次开发/接口对接等所有网站相关业务
    }
     public function tixian()
    {
         
   	$dailiData=Db::name('daili_tixian')->order('id desc')->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);
      return view('',[
         'dailiData'=>$dailiData,
        
        ]);

    }
      public function tixianchuli()
    {
        $id=input('id');
     	$tixianData=Db::name('daili_tixian')->where('a.id',$id)
     	->alias('a')->join('daili b','a.uid=b.id')->field('a.*,b.tixianfangshi,b.hsoukuanren,b.tixianimg,b.tixianzhanghao,b.beizhu')->select()->toArray();

     	  if(request()->isPost()){
         $data=input('get.');
       print_r($data);
       die();
            if($data['status']=2){
                $ress= Db::name('daili')->where('id',$tixianData[0]['uid'])->inc('yue',$tixianData[0]['amount'])->update();  
            }
     
         $res=Db::name('daili_tixian')->where('id',$id)->update($data);
     
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
       }
      return view('',[
         'tixianData'=>$tixianData['0'],
         'left_menu'=>3
        ]);

    }
     public function tixianchulis()
    {
       $data=input('get.');
       $id=$data['id'];
    $status=$data['status'];
     	$tixianData=Db::name('daili_tixian')->where('a.id',$id)
     	->alias('a')->join('daili b','a.uid=b.id')->field('a.*,b.tixianfangshi,b.hsoukuanren,b.tixianimg,b.tixianzhanghao,b.beizhu')->select()->toArray();

         if($status==1){
                 $res=Db::name('daili_tixian')->where('id',$id)->update($data);
      
         if($res){
            return alert('操作成功！','tixian',6,3);
         }else{
            return alert('操作失败！','tixian',5,3);
         }
            }else{
              $ress= Db::name('daili')->where('id',$tixianData[0]['uid'])->inc('yue',$tixianData[0]['amount'])->update(); 
                $res=Db::name('daili_tixian')->where('id',$id)->update($data);
      
         if($res){
            return alert('操作成功！','tixian',6,3);
         }else{
            return alert('操作失败！','tixian',5,3);
         }
            }
       
     
         
     
       

    }
     public function indexedit()
     {
    $id=input('id');
        $edir=Db::name('dailiconfig')->where('id',$id)->find();
       if(request()->isPost()){
         $data=request()->post();
     
        
       
         $res=Db::name('dailiconfig')->where('id',$id)->update($data);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
       }
       return view('',[
       'edir'=>$edir,
        ]);
    }
     public function add(){
      
       if(request()->isPost()){
         $data=request()->post();
         $data['time']=time();
         $data['userpass']=$this->password_salt($data['userpass']);
          $strs="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
         $name=substr(str_shuffle($strs),mt_rand(0,strlen($strs)-11),6);
         $nameyanzheng=Db::name('daili')->where('dwz',$name)->find();
         if($nameyanzheng==null){
          $data['dwz']=$name;
         }else{
          $nameid=Db::name('daili')->max('id');
          $data['dwz']=$name.$nameid;
         }
         $res=Db::name('daili')->insertGetId($data);
         if($res){
        $dwzdata['uid']= $res;
        $dwzdata['durl']= substr(md5(microtime(true)), 0, 6);
        $dwzres=Db::name('dwz')->insertGetId($dwzdata);    
        $datas=Db::name('danqun')->where('id',1)->find();
        unset($datas['id']);
        $datas['uid']=$res;
        $res1=Db::name('danqun')->insertGetId($datas); 
         $paid=Db::name('paid')->where('id',1)->find();
         $paid['uid']=$res;
         unset($paid['id']);
         $paids=Db::name('paid')->insert($paid);
       $danqunlist=Db::name('danqunlist')->where('uid',0)->select()->toArray(); 
       foreach ($danqunlist as $k1 => $v1){
      
        unset($danqunlist[$k1]["id"]);
        $danqunlist[$k1]["uid"]=$res;
      
         }
           $danqunlists=Db::name('danqunlist')->insertAll($danqunlist);
             
            return alert('操作成功！','list',6,3);
         }else{
            return alert('操作失败！','list',5,3);
         }
       }
       return view('',[
      
        ]);
    }
  public function edit(){
       $id=input('id');
        $edir=Db::name('daili')->where('id',$id)->find();
       if(request()->isPost()){
         $data=request()->post();
         $data['time']=time();
         if($edir['userpass']!==$data['userpass']){
             $data['userpass']=$this->password_salt($data['userpass']);    
         }
        
       
         $res=Db::name('daili')->where('id',$id)->update($data);
         if($res){
            return alert('操作成功！','list',6,3);
         }else{
            return alert('操作失败！','list',5,3);
         }
       }
       return view('',[
       'edir'=>$edir,
        ]);
    }
public function list()
    {
    	$dailiData=Db::name('daili')->where('id','>',0)->order('id desc')->select();

      return view('',[
         'dailiData'=>$dailiData,
        
        ]);

    }
    /*添加*/
  public function del()
    {
       $id=input('id');//助手函数

      $res=Db::name('daili')->delete($id);
      $res1=Db::name('paid')->where('uid',$id)->delete();
      $res2=Db::name('danqunlist')->where('uid',$id)->delete();
      $res3=Db::name('danqun')->where('uid',$id)->delete();
      if($res){
            return alert('删除成功!','list',6,3);
         }else{
            return alert('操作失败！','list',5,3);
         } 
    }   
    
    
}
